package org.si.icon;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

/**
 * Defines an abstract implementation of the ScalableIcon interface. This implements the core contract that is required,
 * specifically that when {@link #paintIcon(Component, Graphics, int, int)} is called it should call {@link
 * #paintIcon(Component, Graphics, int, int, int, int)} with the default width and height.
 *
 * @author Matt Nathan
 */
public abstract class AbstractScalableIcon implements ScalableIcon {

    /**
     * Delegates to {@link #paintIcon(Component, Graphics, int, int, int, int)} with the default icon size for width and
     * height.
     *
     * @param c The component to paint to.
     * @param g The Graphics object to paint on.
     * @param x The x coord to paint at.
     * @param y The y coord to paint at.
     */
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        paintIcon(c, g, x, y, getIconWidth(), getIconHeight());
    }





    /**
     * Simple implementation that forwards to {@link #fitInto(Component, int, int, Dimension)} with a new Dimension
     * instance.
     *
     * @param c      The target component which will be passed when paintIcon is called.
     * @param width  The target width for the icon.
     * @param height The target height for the icon.
     * @return The size the icon is happy painting at in the given target size.
     */
    @Override
    public final Dimension fitInto(Component c, int width, int height) {
        Dimension result = new Dimension();
        fitInto(c, width, height, result);
        return result;
    }





    /**
     * Fit this icon into the given width and height and place the result into the results variable.
     *
     * @param c      The component that this will be painted to.
     * @param width  The target width for the icon paint area.
     * @param height The target height for the icon paint area.
     * @param result The place to put the size the icon is hapy painting in.
     */
    public abstract void fitInto(Component c, int width, int height, Dimension result);
}
